// pages/overdueCreate/overdueCreate.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    proId:0,
    content: '',
    images: [],
    type:3
  },

  inputArea1(e) {
    this.setData({ content: e.detail.value });
  },

  onRest() {
    this.setData({ content: '', images: [] });
  },

  /** 领导点评 - 提交 */
  onSubmit() {
    if (this.data.content == '') {
      app.showFailToast('请填写点评内容');
      return false;
    }
    let params = {
      pid: this.data.proId,
      progress: this.data.content,
      images: this.data.images.join(';'),
      type:this.data.type
    };
    this.setData({ loading: true });
    app.request('post', '/api/Project/createOverdue', params)
      .then(res => {
        app.showSuccessToast('发布成功');
        this.setData({ content: '',images:[]});
      })
      .catch(err => console.log(err));
  },


  previewImg2: function (e) {
    let that = this;
    let figureList = that.data.images;
    wx.previewImage({
      current: e.currentTarget.dataset.src,   //当前图片地址
      urls: figureList,        //所有要预览的图片的地址集合 数组形式
    });
  },

  //上传图片
  onChoosePic() {
    let that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        let tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: `${app.globalData.rootUrl}/api/upload/upload`,
          filePath: tempFilePaths[0],
          name: 'file',
          formData: { 'appid': app.appid },
          success: res => {
            let response = JSON.parse(res.data);
            if (res.statusCode == 200) {
              if (response.code == 0) {
                let images = that.data.images;
                images.push(response.thumb);
                that.setData({ images });
              } else {
                app.showFailToast(response.msg);
              }
            } else app.showFailToast('网络错误，请稍后再试');
          }
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.proId != undefined) {
      this.setData({ proId: options.proId });
    }
    if (options.type != undefined) {
      this.setData({ type: options.type });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})